const app = getApp()
const request = (url, options) => {
  return new Promise((resolve, reject) => {
    wx.request({
      url: `${app.globalData.host}${url}`,
      method: options.method,
      data: options.data,
      header: {
        'Content-Type': options.ContentType,
        "appid": 18,
      },
      success(request) {
        resolve(request)
      },
      fail(error) {
        reject(error.data)
      }
    })
  })
}

const get = (url, options = {}) => {
  return request(url, {
    method: 'GET',
    data: options,
    ContentType: 'application/x-www-form-urlencoded; charset=UTF-8'
  })
}

const post = (url, options) => {
  return request(url, {
    method: 'POST',
    data: options,
    ContentType: 'application/x-www-form-urlencoded; charset=UTF-8'
  })
}
const postJson = (url, options) => {
  return request(url, {
    method: 'POST',
    data: options,
    ContentType: 'application/json; charset=UTF-8'
  })
}

module.exports = {
  get,
  post,
  postJson
}